import { createStore, applyMiddleware } from 'redux'
import { initState, reducer } from './reducer'
// 引入插件
import chunk from 'redux-thunk'

const store = createStore(reducer, initState, applyMiddleware(chunk) /*启用异步 dispath action*/)


// 监听store 仓库数据发生改变 
store.subscribe(() => {
  // 获取数据
  const state = store.getState()
  console.log('当前购物车数据', state.car);
  // 数据发生改变  保存本地购物车存储
  localStorage.setItem('car', JSON.stringify(state.car))
})


export default store